package com.music.dao;

import com.laoxuai.beans.annotation.Component;
import com.laoxuai.ibatis.support.BaseDao;
import com.laoxuai.ibatis.util.FieldUtils;
import com.music.pojo.Artist;
import com.music.pojo.Lyric;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.junit.jupiter.api.Test;

import java.sql.Blob;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

@Component
public class LyricDao extends BaseDao<Lyric, Integer> {
    public int insertrewrite(Lyric lyric, Blob content) throws SQLException {
        String sql = "insert into t_lyric(music_id,content,lyric_order,create_time,update_time,is_deleted) values(?,?,?,?,?,?)";
        Object[] param = {lyric.getMusicId(),content,lyric.getLyricOrder(),new java.sql.Date(lyric.getCreateTime().getTime())
        ,lyric.getUpdateTime(),lyric.getIsDeleted()};
        return runner.update(sql, param);
    }


    public List<Lyric> lyricPage(Artist artist, int page, int size) throws SQLException {
        int currentindex=page*size;
        int pagesize=currentindex+size;
        System.out.println(page);
        System.out.println(size);
        String sql="select id,music_id,lyric_order,create_time,update_time,is_deleted from t_artist limit currentindex,pagesize";
        return (List)runner.query(sql,new BeanListHandler<Lyric>(Lyric.class));
    }
}
